"use client"

import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Textarea } from "@/components/ui/textarea"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Progress } from "@/components/ui/progress"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { Slider } from "@/components/ui/slider"
import { Switch } from "@/components/ui/switch"
import { Label } from "@/components/ui/label"
import {
  FileText,
  Lightbulb,
  Target,
  Users,
  Download,
  Eye,
  Edit,
  CheckCircle,
  ArrowRight,
  Sparkles,
  TrendingUp,
  DollarSign,
  Shield,
  BarChart3,
  AlertTriangle,
  Star,
  Zap,
  Calendar,
  Calculator,
} from "lucide-react"
import { useState } from "react"

interface BusinessPlanGeneratorProps {
  onClose: () => void
}

export function BusinessPlanGenerator({ onClose }: BusinessPlanGeneratorProps) {
  const [currentStep, setCurrentStep] = useState(1)
  const [formData, setFormData] = useState({
    // 基本信息
    companyName: "",
    industry: "",
    businessModel: "",
    foundingDate: "",
    location: "",
    website: "",

    // 市场分析
    targetMarket: "",
    marketSize: "",
    marketGrowth: "",
    customerSegments: "",
    customerPainPoints: "",
    marketTrends: "",

    // 产品/服务
    problemStatement: "",
    solution: "",
    uniqueValue: "",
    productFeatures: "",
    developmentStage: "",
    intellectualProperty: "",

    // 竞争分析
    competitors: "",
    competitiveAdvantage: "",
    barriers: "",
    swotStrengths: "",
    swotWeaknesses: "",
    swotOpportunities: "",
    swotThreats: "",

    // 营销策略
    marketingStrategy: "",
    salesChannels: "",
    pricingStrategy: "",
    customerAcquisition: "",
    brandStrategy: "",

    // 运营计划
    operationsModel: "",
    keyActivities: "",
    keyResources: "",
    keyPartners: "",
    supplyChain: "",
    qualityControl: "",

    // 团队管理
    teamSize: "",
    keyPersonnel: "",
    organizationStructure: "",
    advisors: "",
    hiringPlan: "",
    compensation: "",

    // 财务规划
    revenueModel: "",
    revenueProjections: "",
    costStructure: "",
    fundingNeeded: "",
    useOfFunds: "",
    financialProjections: "",
    breakEvenAnalysis: "",

    // 风险分析
    riskFactors: "",
    riskMitigation: "",
    contingencyPlan: "",

    // 实施计划
    timeline: "",
    milestones: "",
    kpis: "",
    exitStrategy: "",
  })

  const [isGenerating, setIsGenerating] = useState(false)
  const [generatedPlan, setGeneratedPlan] = useState(null)
  const [selectedTemplate, setSelectedTemplate] = useState("standard")
  const [includeFinancials, setIncludeFinancials] = useState(true)
  const [includeCharts, setIncludeCharts] = useState(true)
  const [planLength, setPlanLength] = useState([2]) // 1=简版, 2=标准版, 3=详细版

  const steps = [
    { id: 1, title: "基本信息", icon: FileText, description: "公司基础信息" },
    { id: 2, title: "市场分析", icon: Target, description: "目标市场研究" },
    { id: 3, title: "产品方案", icon: Lightbulb, description: "产品服务定义" },
    { id: 4, title: "竞争分析", icon: Shield, description: "竞争环境分析" },
    { id: 5, title: "营销策略", icon: TrendingUp, description: "市场推广计划" },
    { id: 6, title: "运营计划", icon: BarChart3, description: "运营模式设计" },
    { id: 7, title: "团队管理", icon: Users, description: "团队组织架构" },
    { id: 8, title: "财务规划", icon: DollarSign, description: "财务预测分析" },
    { id: 9, title: "风险评估", icon: AlertTriangle, description: "风险识别控制" },
    { id: 10, title: "实施计划", icon: Calendar, description: "执行时间表" },
    { id: 11, title: "生成计划", icon: Sparkles, description: "AI智能生成" },
  ]

  const industries = [
    "互联网/科技",
    "人工智能/机器学习",
    "区块链/加密货币",
    "物联网/智能硬件",
    "电子商务/新零售",
    "移动应用/游戏",
    "企业服务/SaaS",
    "金融科技/支付",
    "教育培训/在线教育",
    "医疗健康/生物技术",
    "新能源/环保科技",
    "智能制造/工业4.0",
    "文娱传媒/内容创作",
    "旅游出行/共享经济",
    "房地产科技",
    "农业科技/食品科技",
    "时尚消费/生活方式",
    "体育健身/运动科技",
    "宠物经济",
    "银发经济",
    "其他",
  ]

  const businessModels = [
    "B2B (企业对企业)",
    "B2C (企业对消费者)",
    "C2C (消费者对消费者)",
    "B2B2C (企业对企业对消费者)",
    "平台模式",
    "订阅模式",
    "免费增值模式",
    "广告模式",
    "佣金模式",
    "授权模式",
    "直销模式",
    "代理模式",
    "其他",
  ]

  const templates = [
    { id: "standard", name: "标准模板", description: "适合大多数行业的通用模板" },
    { id: "tech", name: "科技创新", description: "专为科技公司设计的模板" },
    { id: "retail", name: "零售电商", description: "适合零售和电商企业" },
    { id: "service", name: "服务行业", description: "专为服务型企业设计" },
    { id: "manufacturing", name: "制造业", description: "适合制造和生产企业" },
    { id: "healthcare", name: "医疗健康", description: "专为医疗健康行业设计" },
  ]

  const handleInputChange = (field, value) => {
    setFormData((prev) => ({ ...prev, [field]: value }))
  }

  const handleNext = () => {
    if (currentStep < 11) {
      setCurrentStep(currentStep + 1)
    }
  }

  const handlePrevious = () => {
    if (currentStep > 1) {
      setCurrentStep(currentStep - 1)
    }
  }

  const generateBusinessPlan = async () => {
    setIsGenerating(true)

    // 模拟AI生成过程
    await new Promise((resolve) => setTimeout(resolve, 5000))

    const mockPlan = {
      executiveSummary: `${formData.companyName}是一家专注于${formData.industry}领域的创新企业，成立于${formData.foundingDate}，总部位于${formData.location}。我们致力于通过${formData.solution}解决${formData.problemStatement}的问题，采用${formData.businessModel}的商业模式服务于${formData.targetMarket}市场。

公司的核心竞争优势在于${formData.competitiveAdvantage}，预计在未来3年内实现${formData.revenueProjections}的营收目标。我们计划融资${formData.fundingNeeded}，主要用于${formData.useOfFunds}，以实现快速增长和市场扩张。`,

      companyDescription: `${formData.companyName}专注于${formData.industry}行业，我们的使命是通过创新技术和优质服务，为客户创造价值。公司采用${formData.businessModel}模式，目前处于${formData.developmentStage}阶段。

我们的核心产品/服务包括：${formData.productFeatures}。公司拥有${formData.intellectualProperty}等知识产权保护，确保竞争优势的可持续性。`,

      marketAnalysis: `目标市场分析显示，${formData.targetMarket}市场规模达到${formData.marketSize}，年增长率约为${formData.marketGrowth}。市场主要趋势包括：${formData.marketTrends}。

客户细分：${formData.customerSegments}
客户痛点：${formData.customerPainPoints}

我们识别出的主要市场机会包括新兴技术应用、消费升级趋势、政策支持等因素，预计将推动市场持续增长。`,

      competitiveAnalysis: `竞争环境分析：
主要竞争对手：${formData.competitors}
竞争优势：${formData.competitiveAdvantage}
进入壁垒：${formData.barriers}

SWOT分析：
优势(Strengths)：${formData.swotStrengths}
劣势(Weaknesses)：${formData.swotWeaknesses}
机会(Opportunities)：${formData.swotOpportunities}
威胁(Threats)：${formData.swotThreats}`,

      productService: `产品/服务详述：
核心问题：${formData.problemStatement}
解决方案：${formData.solution}
独特价值：${formData.uniqueValue}
产品特性：${formData.productFeatures}
开发阶段：${formData.developmentStage}

我们的产品/服务通过创新的技术和设计，为客户提供卓越的体验和价值。`,

      marketingStrategy: `营销策略：
整体策略：${formData.marketingStrategy}
销售渠道：${formData.salesChannels}
定价策略：${formData.pricingStrategy}
获客策略：${formData.customerAcquisition}
品牌策略：${formData.brandStrategy}

我们将采用多渠道营销方式，通过数字化营销、合作伙伴推广、口碑营销等方式快速获取客户。`,

      operationsModel: `运营模式：
运营模型：${formData.operationsModel}
关键活动：${formData.keyActivities}
关键资源：${formData.keyResources}
关键合作：${formData.keyPartners}
供应链：${formData.supplyChain}
质量控制：${formData.qualityControl}

我们建立了高效的运营体系，确保产品质量和服务水平。`,

      teamManagement: `团队管理：
团队规模：${formData.teamSize}
核心人员：${formData.keyPersonnel}
组织架构：${formData.organizationStructure}
顾问团队：${formData.advisors}
招聘计划：${formData.hiringPlan}
薪酬体系：${formData.compensation}

我们拥有经验丰富的管理团队和专业的技术团队，具备实现业务目标的能力。`,

      financialProjections: `财务预测：
收入模式：${formData.revenueModel}
收入预测：${formData.revenueProjections}
成本结构：${formData.costStructure}
融资需求：${formData.fundingNeeded}
资金用途：${formData.useOfFunds}
盈亏平衡：${formData.breakEvenAnalysis}

基于市场分析和运营计划，我们预计在第二年实现盈亏平衡，第三年实现规模化盈利。`,

      riskAnalysis: `风险分析：
主要风险：${formData.riskFactors}
风险缓解：${formData.riskMitigation}
应急计划：${formData.contingencyPlan}

我们已识别出主要风险因素，并制定了相应的风险控制和应急预案。`,

      implementationPlan: `实施计划：
时间规划：${formData.timeline}
关键里程碑：${formData.milestones}
关键指标：${formData.kpis}
退出策略：${formData.exitStrategy}

我们制定了详细的实施计划和时间表，确保各项目标按时达成。`,

      appendix: {
        financialCharts: includeFinancials,
        marketCharts: includeCharts,
        teamBios: true,
        productImages: true,
      },
    }

    setGeneratedPlan(mockPlan)
    setIsGenerating(false)
    setCurrentStep(11)
  }

  const renderStepContent = () => {
    switch (currentStep) {
      case 1:
        return (
          <div className="space-y-6">
            <div className="text-center mb-8">
              <FileText className="w-12 h-12 text-blue-600 mx-auto mb-4" />
              <h2 className="text-2xl font-bold text-slate-900 mb-2">基本信息</h2>
              <p className="text-slate-600">建立您企业的基础档案</p>
            </div>

            <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
              <div className="space-y-4">
                <div>
                  <label className="text-sm font-medium text-slate-700">公司名称 *</label>
                  <Input
                    placeholder="输入公司全称"
                    value={formData.companyName}
                    onChange={(e) => handleInputChange("companyName", e.target.value)}
                    className="mt-1"
                  />
                </div>
                <div>
                  <label className="text-sm font-medium text-slate-700">所属行业 *</label>
                  <Select value={formData.industry} onValueChange={(value) => handleInputChange("industry", value)}>
                    <SelectTrigger className="mt-1">
                      <SelectValue placeholder="选择行业" />
                    </SelectTrigger>
                    <SelectContent>
                      {industries.map((industry) => (
                        <SelectItem key={industry} value={industry}>
                          {industry}
                        </SelectItem>
                      ))}
                    </SelectContent>
                  </Select>
                </div>
                <div>
                  <label className="text-sm font-medium text-slate-700">商业模式 *</label>
                  <Select
                    value={formData.businessModel}
                    onValueChange={(value) => handleInputChange("businessModel", value)}
                  >
                    <SelectTrigger className="mt-1">
                      <SelectValue placeholder="选择商业模式" />
                    </SelectTrigger>
                    <SelectContent>
                      {businessModels.map((model) => (
                        <SelectItem key={model} value={model}>
                          {model}
                        </SelectItem>
                      ))}
                    </SelectContent>
                  </Select>
                </div>
              </div>
              <div className="space-y-4">
                <div>
                  <label className="text-sm font-medium text-slate-700">成立时间</label>
                  <Input
                    type="date"
                    value={formData.foundingDate}
                    onChange={(e) => handleInputChange("foundingDate", e.target.value)}
                    className="mt-1"
                  />
                </div>
                <div>
                  <label className="text-sm font-medium text-slate-700">公司地址</label>
                  <Input
                    placeholder="总部所在城市"
                    value={formData.location}
                    onChange={(e) => handleInputChange("location", e.target.value)}
                    className="mt-1"
                  />
                </div>
                <div>
                  <label className="text-sm font-medium text-slate-700">公司网站</label>
                  <Input
                    placeholder="https://www.example.com"
                    value={formData.website}
                    onChange={(e) => handleInputChange("website", e.target.value)}
                    className="mt-1"
                  />
                </div>
              </div>
            </div>

            {/* 模板选择 */}
            <div className="mt-8">
              <label className="text-sm font-medium text-slate-700 mb-4 block">选择计划书模板</label>
              <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
                {templates.map((template) => (
                  <Card
                    key={template.id}
                    className={`cursor-pointer transition-all ${
                      selectedTemplate === template.id ? "border-blue-500 bg-blue-50" : "hover:border-slate-300"
                    }`}
                    onClick={() => setSelectedTemplate(template.id)}
                  >
                    <CardContent className="p-4">
                      <div className="flex items-center space-x-2 mb-2">
                        <div
                          className={`w-3 h-3 rounded-full ${
                            selectedTemplate === template.id ? "bg-blue-500" : "bg-slate-300"
                          }`}
                        />
                        <h4 className="font-medium">{template.name}</h4>
                      </div>
                      <p className="text-sm text-slate-600">{template.description}</p>
                    </CardContent>
                  </Card>
                ))}
              </div>
            </div>
          </div>
        )

      case 2:
        return (
          <div className="space-y-6">
            <div className="text-center mb-8">
              <Target className="w-12 h-12 text-green-600 mx-auto mb-4" />
              <h2 className="text-2xl font-bold text-slate-900 mb-2">市场分析</h2>
              <p className="text-slate-600">深入了解您的目标市场</p>
            </div>

            <div className="space-y-6">
              <div>
                <label className="text-sm font-medium text-slate-700">目标市场描述 *</label>
                <Textarea
                  placeholder="详细描述您的目标客户群体，包括人口统计、行为特征、需求特点等"
                  value={formData.targetMarket}
                  onChange={(e) => handleInputChange("targetMarket", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                  <label className="text-sm font-medium text-slate-700">市场规模 *</label>
                  <Input
                    placeholder="例如：100亿元人民币 TAM"
                    value={formData.marketSize}
                    onChange={(e) => handleInputChange("marketSize", e.target.value)}
                    className="mt-1"
                  />
                </div>
                <div>
                  <label className="text-sm font-medium text-slate-700">市场增长率</label>
                  <Input
                    placeholder="例如：年增长率15%"
                    value={formData.marketGrowth}
                    onChange={(e) => handleInputChange("marketGrowth", e.target.value)}
                    className="mt-1"
                  />
                </div>
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">客户细分</label>
                <Textarea
                  placeholder="将目标市场细分为不同的客户群体，描述每个群体的特征"
                  value={formData.customerSegments}
                  onChange={(e) => handleInputChange("customerSegments", e.target.value)}
                  className="mt-1 min-h-[80px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">客户痛点分析 *</label>
                <Textarea
                  placeholder="分析目标客户面临的主要问题和挑战"
                  value={formData.customerPainPoints}
                  onChange={(e) => handleInputChange("customerPainPoints", e.target.value)}
                  className="mt-1 min-h-[80px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">市场趋势</label>
                <Textarea
                  placeholder="描述影响您行业的主要市场趋势和发展方向"
                  value={formData.marketTrends}
                  onChange={(e) => handleInputChange("marketTrends", e.target.value)}
                  className="mt-1 min-h-[80px]"
                />
              </div>
            </div>
          </div>
        )

      case 3:
        return (
          <div className="space-y-6">
            <div className="text-center mb-8">
              <Lightbulb className="w-12 h-12 text-yellow-600 mx-auto mb-4" />
              <h2 className="text-2xl font-bold text-slate-900 mb-2">产品与服务</h2>
              <p className="text-slate-600">定义您的核心产品和服务</p>
            </div>

            <div className="space-y-6">
              <div>
                <label className="text-sm font-medium text-slate-700">问题陈述 *</label>
                <Textarea
                  placeholder="清晰描述您要解决的核心问题，这个问题的严重性和普遍性"
                  value={formData.problemStatement}
                  onChange={(e) => handleInputChange("problemStatement", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">解决方案 *</label>
                <Textarea
                  placeholder="详细描述您的产品或服务如何解决上述问题"
                  value={formData.solution}
                  onChange={(e) => handleInputChange("solution", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">独特价值主张 *</label>
                <Textarea
                  placeholder="您的产品/服务与竞争对手相比有什么独特优势？为什么客户会选择您？"
                  value={formData.uniqueValue}
                  onChange={(e) => handleInputChange("uniqueValue", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">产品特性与功能</label>
                <Textarea
                  placeholder="详细列出产品的主要特性、功能模块和技术规格"
                  value={formData.productFeatures}
                  onChange={(e) => handleInputChange("productFeatures", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                  <label className="text-sm font-medium text-slate-700">开发阶段</label>
                  <Select
                    value={formData.developmentStage}
                    onValueChange={(value) => handleInputChange("developmentStage", value)}
                  >
                    <SelectTrigger className="mt-1">
                      <SelectValue placeholder="选择开发阶段" />
                    </SelectTrigger>
                    <SelectContent>
                      <SelectItem value="concept">概念阶段</SelectItem>
                      <SelectItem value="prototype">原型开发</SelectItem>
                      <SelectItem value="mvp">MVP测试</SelectItem>
                      <SelectItem value="beta">Beta版本</SelectItem>
                      <SelectItem value="launched">已上线</SelectItem>
                      <SelectItem value="scaling">规模化</SelectItem>
                    </SelectContent>
                  </Select>
                </div>
                <div>
                  <label className="text-sm font-medium text-slate-700">知识产权</label>
                  <Input
                    placeholder="专利、商标、版权等"
                    value={formData.intellectualProperty}
                    onChange={(e) => handleInputChange("intellectualProperty", e.target.value)}
                    className="mt-1"
                  />
                </div>
              </div>
            </div>
          </div>
        )

      case 4:
        return (
          <div className="space-y-6">
            <div className="text-center mb-8">
              <Shield className="w-12 h-12 text-purple-600 mx-auto mb-4" />
              <h2 className="text-2xl font-bold text-slate-900 mb-2">竞争分析</h2>
              <p className="text-slate-600">分析竞争环境和您的优势</p>
            </div>

            <div className="space-y-6">
              <div>
                <label className="text-sm font-medium text-slate-700">主要竞争对手 *</label>
                <Textarea
                  placeholder="列出3-5个主要竞争对手，分析他们的产品、市场地位、优势和劣势"
                  value={formData.competitors}
                  onChange={(e) => handleInputChange("competitors", e.target.value)}
                  className="mt-1 min-h-[120px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">竞争优势 *</label>
                <Textarea
                  placeholder="详细说明您相对于竞争对手的核心优势"
                  value={formData.competitiveAdvantage}
                  onChange={(e) => handleInputChange("competitiveAdvantage", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">进入壁垒</label>
                <Textarea
                  placeholder="分析行业的进入壁垒，以及您如何建立自己的护城河"
                  value={formData.barriers}
                  onChange={(e) => handleInputChange("barriers", e.target.value)}
                  className="mt-1 min-h-[80px]"
                />
              </div>

              {/* SWOT分析 */}
              <div>
                <h3 className="text-lg font-semibold text-slate-900 mb-4">SWOT分析</h3>
                <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
                  <div>
                    <label className="text-sm font-medium text-green-700">优势 (Strengths)</label>
                    <Textarea
                      placeholder="列出您的内部优势"
                      value={formData.swotStrengths}
                      onChange={(e) => handleInputChange("swotStrengths", e.target.value)}
                      className="mt-1 min-h-[80px] border-green-200 focus:border-green-400"
                    />
                  </div>
                  <div>
                    <label className="text-sm font-medium text-red-700">劣势 (Weaknesses)</label>
                    <Textarea
                      placeholder="诚实分析您的不足"
                      value={formData.swotWeaknesses}
                      onChange={(e) => handleInputChange("swotWeaknesses", e.target.value)}
                      className="mt-1 min-h-[80px] border-red-200 focus:border-red-400"
                    />
                  </div>
                  <div>
                    <label className="text-sm font-medium text-blue-700">机会 (Opportunities)</label>
                    <Textarea
                      placeholder="识别外部机会"
                      value={formData.swotOpportunities}
                      onChange={(e) => handleInputChange("swotOpportunities", e.target.value)}
                      className="mt-1 min-h-[80px] border-blue-200 focus:border-blue-400"
                    />
                  </div>
                  <div>
                    <label className="text-sm font-medium text-yellow-700">威胁 (Threats)</label>
                    <Textarea
                      placeholder="分析外部威胁"
                      value={formData.swotThreats}
                      onChange={(e) => handleInputChange("swotThreats", e.target.value)}
                      className="mt-1 min-h-[80px] border-yellow-200 focus:border-yellow-400"
                    />
                  </div>
                </div>
              </div>
            </div>
          </div>
        )

      case 5:
        return (
          <div className="space-y-6">
            <div className="text-center mb-8">
              <TrendingUp className="w-12 h-12 text-indigo-600 mx-auto mb-4" />
              <h2 className="text-2xl font-bold text-slate-900 mb-2">营销策略</h2>
              <p className="text-slate-600">制定市场推广和销售计划</p>
            </div>

            <div className="space-y-6">
              <div>
                <label className="text-sm font-medium text-slate-700">整体营销策略 *</label>
                <Textarea
                  placeholder="描述您的整体营销方法和策略思路"
                  value={formData.marketingStrategy}
                  onChange={(e) => handleInputChange("marketingStrategy", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">销售渠道 *</label>
                <Textarea
                  placeholder="详细说明您的销售渠道：直销、代理、在线、零售等"
                  value={formData.salesChannels}
                  onChange={(e) => handleInputChange("salesChannels", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">定价策略 *</label>
                <Textarea
                  placeholder="说明您的定价模式、价格水平和定价理由"
                  value={formData.pricingStrategy}
                  onChange={(e) => handleInputChange("pricingStrategy", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">客户获取策略</label>
                <Textarea
                  placeholder="详细说明如何获取第一批客户，以及后续的客户增长策略"
                  value={formData.customerAcquisition}
                  onChange={(e) => handleInputChange("customerAcquisition", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">品牌策略</label>
                <Textarea
                  placeholder="描述您的品牌定位、品牌形象和品牌传播策略"
                  value={formData.brandStrategy}
                  onChange={(e) => handleInputChange("brandStrategy", e.target.value)}
                  className="mt-1 min-h-[80px]"
                />
              </div>
            </div>
          </div>
        )

      case 6:
        return (
          <div className="space-y-6">
            <div className="text-center mb-8">
              <BarChart3 className="w-12 h-12 text-orange-600 mx-auto mb-4" />
              <h2 className="text-2xl font-bold text-slate-900 mb-2">运营计划</h2>
              <p className="text-slate-600">设计高效的运营模式</p>
            </div>

            <div className="space-y-6">
              <div>
                <label className="text-sm font-medium text-slate-700">运营模式 *</label>
                <Textarea
                  placeholder="描述您的整体运营模式和业务流程"
                  value={formData.operationsModel}
                  onChange={(e) => handleInputChange("operationsModel", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">关键活动</label>
                <Textarea
                  placeholder="列出为了成功运营业务必须执行的关键活动"
                  value={formData.keyActivities}
                  onChange={(e) => handleInputChange("keyActivities", e.target.value)}
                  className="mt-1 min-h-[80px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">关键资源</label>
                <Textarea
                  placeholder="识别业务运营所需的关键资源：人力、技术、资金、设备等"
                  value={formData.keyResources}
                  onChange={(e) => handleInputChange("keyResources", e.target.value)}
                  className="mt-1 min-h-[80px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">关键合作伙伴</label>
                <Textarea
                  placeholder="列出重要的合作伙伴和供应商"
                  value={formData.keyPartners}
                  onChange={(e) => handleInputChange("keyPartners", e.target.value)}
                  className="mt-1 min-h-[80px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">供应链管理</label>
                <Textarea
                  placeholder="描述您的供应链策略和管理方式"
                  value={formData.supplyChain}
                  onChange={(e) => handleInputChange("supplyChain", e.target.value)}
                  className="mt-1 min-h-[80px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">质量控制</label>
                <Textarea
                  placeholder="说明质量保证和控制措施"
                  value={formData.qualityControl}
                  onChange={(e) => handleInputChange("qualityControl", e.target.value)}
                  className="mt-1 min-h-[80px]"
                />
              </div>
            </div>
          </div>
        )

      case 7:
        return (
          <div className="space-y-6">
            <div className="text-center mb-8">
              <Users className="w-12 h-12 text-cyan-600 mx-auto mb-4" />
              <h2 className="text-2xl font-bold text-slate-900 mb-2">团队管理</h2>
              <p className="text-slate-600">构建强大的团队组织</p>
            </div>

            <div className="space-y-6">
              <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                  <label className="text-sm font-medium text-slate-700">当前团队规模</label>
                  <Input
                    placeholder="例如：15人"
                    value={formData.teamSize}
                    onChange={(e) => handleInputChange("teamSize", e.target.value)}
                    className="mt-1"
                  />
                </div>
                <div>
                  <label className="text-sm font-medium text-slate-700">组织架构</label>
                  <Input
                    placeholder="例如：扁平化管理"
                    value={formData.organizationStructure}
                    onChange={(e) => handleInputChange("organizationStructure", e.target.value)}
                    className="mt-1"
                  />
                </div>
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">核心团队成员 *</label>
                <Textarea
                  placeholder="详细介绍核心团队成员的背景、经验和职责"
                  value={formData.keyPersonnel}
                  onChange={(e) => handleInputChange("keyPersonnel", e.target.value)}
                  className="mt-1 min-h-[120px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">顾问团队</label>
                <Textarea
                  placeholder="介绍您的顾问团队和他们的专业背景"
                  value={formData.advisors}
                  onChange={(e) => handleInputChange("advisors", e.target.value)}
                  className="mt-1 min-h-[80px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">招聘计划</label>
                <Textarea
                  placeholder="未来12-24个月的人员招聘计划"
                  value={formData.hiringPlan}
                  onChange={(e) => handleInputChange("hiringPlan", e.target.value)}
                  className="mt-1 min-h-[80px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">薪酬激励体系</label>
                <Textarea
                  placeholder="描述薪酬结构、股权激励和绩效考核体系"
                  value={formData.compensation}
                  onChange={(e) => handleInputChange("compensation", e.target.value)}
                  className="mt-1 min-h-[80px]"
                />
              </div>
            </div>
          </div>
        )

      case 8:
        return (
          <div className="space-y-6">
            <div className="text-center mb-8">
              <DollarSign className="w-12 h-12 text-green-600 mx-auto mb-4" />
              <h2 className="text-2xl font-bold text-slate-900 mb-2">财务规划</h2>
              <p className="text-slate-600">制定详细的财务预测</p>
            </div>

            <div className="space-y-6">
              <div>
                <label className="text-sm font-medium text-slate-700">收入模式 *</label>
                <Textarea
                  placeholder="详细说明您的收入来源和盈利模式"
                  value={formData.revenueModel}
                  onChange={(e) => handleInputChange("revenueModel", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">收入预测 *</label>
                <Textarea
                  placeholder="提供未来3-5年的收入预测和增长假设"
                  value={formData.revenueProjections}
                  onChange={(e) => handleInputChange("revenueProjections", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">成本结构 *</label>
                <Textarea
                  placeholder="详细分析固定成本、变动成本和主要支出项目"
                  value={formData.costStructure}
                  onChange={(e) => handleInputChange("costStructure", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                  <label className="text-sm font-medium text-slate-700">融资需求 *</label>
                  <Input
                    placeholder="例如：500万元"
                    value={formData.fundingNeeded}
                    onChange={(e) => handleInputChange("fundingNeeded", e.target.value)}
                    className="mt-1"
                  />
                </div>
                <div>
                  <label className="text-sm font-medium text-slate-700">盈亏平衡点</label>
                  <Input
                    placeholder="例如：第18个月"
                    value={formData.breakEvenAnalysis}
                    onChange={(e) => handleInputChange("breakEvenAnalysis", e.target.value)}
                    className="mt-1"
                  />
                </div>
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">资金用途 *</label>
                <Textarea
                  placeholder="详细说明融资资金的具体用途和分配"
                  value={formData.useOfFunds}
                  onChange={(e) => handleInputChange("useOfFunds", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">财务预测详情</label>
                <Textarea
                  placeholder="提供详细的财务预测，包括损益表、现金流量表等关键财务指标"
                  value={formData.financialProjections}
                  onChange={(e) => handleInputChange("financialProjections", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>
            </div>
          </div>
        )

      case 9:
        return (
          <div className="space-y-6">
            <div className="text-center mb-8">
              <AlertTriangle className="w-12 h-12 text-red-600 mx-auto mb-4" />
              <h2 className="text-2xl font-bold text-slate-900 mb-2">风险评估</h2>
              <p className="text-slate-600">识别和管控业务风险</p>
            </div>

            <div className="space-y-6">
              <div>
                <label className="text-sm font-medium text-slate-700">主要风险因素 *</label>
                <Textarea
                  placeholder="识别可能影响业务的主要风险：市场风险、技术风险、运营风险、财务风险等"
                  value={formData.riskFactors}
                  onChange={(e) => handleInputChange("riskFactors", e.target.value)}
                  className="mt-1 min-h-[120px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">风险缓解措施 *</label>
                <Textarea
                  placeholder="针对每个主要风险，说明相应的预防和缓解措施"
                  value={formData.riskMitigation}
                  onChange={(e) => handleInputChange("riskMitigation", e.target.value)}
                  className="mt-1 min-h-[120px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">应急预案</label>
                <Textarea
                  placeholder="制定应对重大风险事件的应急计划和备选方案"
                  value={formData.contingencyPlan}
                  onChange={(e) => handleInputChange("contingencyPlan", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>
            </div>
          </div>
        )

      case 10:
        return (
          <div className="space-y-6">
            <div className="text-center mb-8">
              <Calendar className="w-12 h-12 text-blue-600 mx-auto mb-4" />
              <h2 className="text-2xl font-bold text-slate-900 mb-2">实施计划</h2>
              <p className="text-slate-600">制定详细的执行路线图</p>
            </div>

            <div className="space-y-6">
              <div>
                <label className="text-sm font-medium text-slate-700">时间规划 *</label>
                <Textarea
                  placeholder="制定未来12-36个月的详细时间规划"
                  value={formData.timeline}
                  onChange={(e) => handleInputChange("timeline", e.target.value)}
                  className="mt-1 min-h-[120px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">关键里程碑 *</label>
                <Textarea
                  placeholder="列出重要的里程碑节点和预期完成时间"
                  value={formData.milestones}
                  onChange={(e) => handleInputChange("milestones", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">关键绩效指标 (KPIs)</label>
                <Textarea
                  placeholder="定义用于衡量业务成功的关键指标"
                  value={formData.kpis}
                  onChange={(e) => handleInputChange("kpis", e.target.value)}
                  className="mt-1 min-h-[100px]"
                />
              </div>

              <div>
                <label className="text-sm font-medium text-slate-700">退出策略</label>
                <Textarea
                  placeholder="描述可能的退出方式：IPO、并购、管理层收购等"
                  value={formData.exitStrategy}
                  onChange={(e) => handleInputChange("exitStrategy", e.target.value)}
                  className="mt-1 min-h-[80px]"
                />
              </div>
            </div>
          </div>
        )

      case 11:
        return (
          <div className="space-y-6">
            <div className="text-center mb-8">
              <Sparkles className="w-12 h-12 text-purple-600 mx-auto mb-4" />
              <h2 className="text-2xl font-bold text-slate-900 mb-2">生成设置</h2>
              <p className="text-slate-600">自定义您的商业计划书</p>
            </div>

            {/* 生成选项 */}
            <Card>
              <CardHeader>
                <CardTitle>生成选项</CardTitle>
              </CardHeader>
              <CardContent className="space-y-6">
                <div>
                  <Label className="text-base font-medium">计划书详细程度</Label>
                  <div className="mt-2">
                    <Slider
                      value={planLength}
                      onValueChange={setPlanLength}
                      max={3}
                      min={1}
                      step={1}
                      className="w-full"
                    />
                    <div className="flex justify-between text-sm text-slate-600 mt-1">
                      <span>简版</span>
                      <span>标准版</span>
                      <span>详细版</span>
                    </div>
                  </div>
                  <p className="text-sm text-slate-600 mt-2">
                    {planLength[0] === 1 && "简版：15-20页，适合快速概览"}
                    {planLength[0] === 2 && "标准版：25-35页，适合投资展示"}
                    {planLength[0] === 3 && "详细版：40-60页，适合详细分析"}
                  </p>
                </div>

                <div className="flex items-center justify-between">
                  <div>
                    <Label className="text-base font-medium">包含财务图表</Label>
                    <p className="text-sm text-slate-600">自动生成收入预测、成本分析等图表</p>
                  </div>
                  <Switch checked={includeFinancials} onCheckedChange={setIncludeFinancials} />
                </div>

                <div className="flex items-center justify-between">
                  <div>
                    <Label className="text-base font-medium">包含市场分析图表</Label>
                    <p className="text-sm text-slate-600">生成市场规模、竞争分析等可视化图表</p>
                  </div>
                  <Switch checked={includeCharts} onCheckedChange={setIncludeCharts} />
                </div>
              </CardContent>
            </Card>

            {isGenerating ? (
              <div className="text-center py-12">
                <Sparkles className="w-12 h-12 text-blue-600 mx-auto mb-4 animate-pulse" />
                <h3 className="text-lg font-semibold text-slate-900 mb-2">AI正在生成您的商业计划书</h3>
                <p className="text-slate-600 mb-4">正在分析您的信息并生成专业的商业计划书...</p>
                <Progress value={75} className="w-64 mx-auto mb-4" />
                <div className="space-y-2 text-sm text-slate-500">
                  <div className="flex items-center justify-center space-x-2">
                    <CheckCircle className="w-4 h-4 text-green-600" />
                    <span>分析市场数据</span>
                  </div>
                  <div className="flex items-center justify-center space-x-2">
                    <CheckCircle className="w-4 h-4 text-green-600" />
                    <span>生成财务预测</span>
                  </div>
                  <div className="flex items-center justify-center space-x-2">
                    <Zap className="w-4 h-4 text-blue-600 animate-pulse" />
                    <span>优化内容结构</span>
                  </div>
                  <div className="flex items-center justify-center space-x-2">
                    <div className="w-4 h-4 border-2 border-slate-300 rounded-full" />
                    <span>生成最终文档</span>
                  </div>
                </div>
              </div>
            ) : generatedPlan ? (
              <div className="space-y-6">
                <div className="text-center">
                  <CheckCircle className="w-12 h-12 text-green-600 mx-auto mb-4" />
                  <h3 className="text-lg font-semibold text-slate-900 mb-2">商业计划书生成完成！</h3>
                  <p className="text-slate-600">您的专业商业计划书已经准备就绪</p>
                </div>

                <div className="grid grid-cols-1 md:grid-cols-4 gap-4">
                  <Button className="flex items-center justify-center space-x-2">
                    <Eye className="w-4 h-4" />
                    <span>在线预览</span>
                  </Button>
                  <Button variant="outline" className="flex items-center justify-center space-x-2 bg-transparent">
                    <Edit className="w-4 h-4" />
                    <span>编辑修改</span>
                  </Button>
                  <Button variant="outline" className="flex items-center justify-center space-x-2 bg-transparent">
                    <Download className="w-4 h-4" />
                    <span>下载PDF</span>
                  </Button>
                  <Button variant="outline" className="flex items-center justify-center space-x-2 bg-transparent">
                    <FileText className="w-4 h-4" />
                    <span>下载PPT</span>
                  </Button>
                </div>

                {/* 计划书预览 */}
                <Tabs defaultValue="summary" className="w-full">
                  <TabsList className="grid w-full grid-cols-4">
                    <TabsTrigger value="summary">执行摘要</TabsTrigger>
                    <TabsTrigger value="market">市场分析</TabsTrigger>
                    <TabsTrigger value="financial">财务预测</TabsTrigger>
                    <TabsTrigger value="team">团队介绍</TabsTrigger>
                  </TabsList>

                  <TabsContent value="summary" className="mt-4">
                    <Card>
                      <CardHeader>
                        <CardTitle>执行摘要</CardTitle>
                      </CardHeader>
                      <CardContent>
                        <p className="text-sm text-slate-700 leading-relaxed">{generatedPlan.executiveSummary}</p>
                      </CardContent>
                    </Card>
                  </TabsContent>

                  <TabsContent value="market" className="mt-4">
                    <Card>
                      <CardHeader>
                        <CardTitle>市场分析</CardTitle>
                      </CardHeader>
                      <CardContent>
                        <p className="text-sm text-slate-700 leading-relaxed">{generatedPlan.marketAnalysis}</p>
                      </CardContent>
                    </Card>
                  </TabsContent>

                  <TabsContent value="financial" className="mt-4">
                    <Card>
                      <CardHeader>
                        <CardTitle>财务预测</CardTitle>
                      </CardHeader>
                      <CardContent>
                        <p className="text-sm text-slate-700 leading-relaxed">{generatedPlan.financialProjections}</p>
                      </CardContent>
                    </Card>
                  </TabsContent>

                  <TabsContent value="team" className="mt-4">
                    <Card>
                      <CardHeader>
                        <CardTitle>团队管理</CardTitle>
                      </CardHeader>
                      <CardContent>
                        <p className="text-sm text-slate-700 leading-relaxed">{generatedPlan.teamManagement}</p>
                      </CardContent>
                    </Card>
                  </TabsContent>
                </Tabs>

                {/* 质量评分 */}
                <Card className="bg-gradient-to-r from-blue-50 to-purple-50 border-blue-200">
                  <CardContent className="p-6">
                    <div className="flex items-center justify-between mb-4">
                      <h4 className="font-semibold text-slate-900">计划书质量评分</h4>
                      <div className="flex items-center space-x-1">
                        {[1, 2, 3, 4, 5].map((star) => (
                          <Star key={star} className="w-5 h-5 fill-yellow-400 text-yellow-400" />
                        ))}
                        <span className="ml-2 font-semibold">4.8/5.0</span>
                      </div>
                    </div>
                    <div className="grid grid-cols-2 md:grid-cols-4 gap-4 text-sm">
                      <div className="text-center">
                        <div className="font-semibold text-green-600">95%</div>
                        <div className="text-slate-600">内容完整度</div>
                      </div>
                      <div className="text-center">
                        <div className="font-semibold text-blue-600">92%</div>
                        <div className="text-slate-600">逻辑清晰度</div>
                      </div>
                      <div className="text-center">
                        <div className="font-semibold text-purple-600">88%</div>
                        <div className="text-slate-600">数据准确性</div>
                      </div>
                      <div className="text-center">
                        <div className="font-semibold text-orange-600">90%</div>
                        <div className="text-slate-600">专业程度</div>
                      </div>
                    </div>
                  </CardContent>
                </Card>
              </div>
            ) : (
              <div className="text-center py-12">
                <Calculator className="w-12 h-12 text-slate-400 mx-auto mb-4" />
                <h3 className="text-lg font-semibold text-slate-900 mb-2">准备生成商业计划书</h3>
                <p className="text-slate-600 mb-6">基于您提供的详细信息，AI将为您生成一份专业的商业计划书</p>
                <Button
                  onClick={generateBusinessPlan}
                  className="px-8"
                  disabled={!formData.companyName || !formData.industry}
                >
                  <Sparkles className="w-4 h-4 mr-2" />
                  开始生成
                </Button>
              </div>
            )}
          </div>
        )

      default:
        return null
    }
  }

  return (
    <Dialog open={true} onOpenChange={onClose}>
      <DialogContent className="max-w-6xl max-h-[90vh] overflow-y-auto">
        <DialogHeader>
          <DialogTitle className="flex items-center space-x-2">
            <FileText className="w-5 h-5" />
            <span>AI商业计划书生成器</span>
          </DialogTitle>
        </DialogHeader>

        {/* 步骤指示器 */}
        <div className="flex items-center justify-between mb-8 overflow-x-auto">
          {steps.map((step, index) => {
            const Icon = step.icon
            const isActive = currentStep === step.id
            const isCompleted = currentStep > step.id

            return (
              <div key={step.id} className="flex items-center min-w-0">
                <div className="flex flex-col items-center">
                  <div
                    className={`flex items-center justify-center w-10 h-10 rounded-full border-2 ${
                      isActive
                        ? "border-blue-600 bg-blue-600 text-white"
                        : isCompleted
                          ? "border-green-600 bg-green-600 text-white"
                          : "border-slate-300 text-slate-400"
                    }`}
                  >
                    {isCompleted ? <CheckCircle className="w-5 h-5" /> : <Icon className="w-5 h-5" />}
                  </div>
                  <div className="mt-2 text-center">
                    <div
                      className={`text-xs font-medium ${
                        isActive ? "text-blue-600" : isCompleted ? "text-green-600" : "text-slate-400"
                      }`}
                    >
                      {step.title}
                    </div>
                    <div className="text-xs text-slate-500 mt-1">{step.description}</div>
                  </div>
                </div>
                {index < steps.length - 1 && <ArrowRight className="w-4 h-4 text-slate-300 mx-2 flex-shrink-0" />}
              </div>
            )
          })}
        </div>

        {/* 进度条 */}
        <div className="mb-6">
          <div className="flex justify-between items-center mb-2">
            <span className="text-sm font-medium text-slate-700">
              步骤 {currentStep} / {steps.length}
            </span>
            <span className="text-sm text-slate-500">{Math.round((currentStep / steps.length) * 100)}% 完成</span>
          </div>
          <Progress value={(currentStep / steps.length) * 100} className="h-2" />
        </div>

        {/* 步骤内容 */}
        <div className="min-h-[500px]">{renderStepContent()}</div>

        {/* 导航按钮 */}
        {currentStep < 11 && (
          <div className="flex justify-between mt-8">
            <Button variant="outline" onClick={handlePrevious} disabled={currentStep === 1}>
              上一步
            </Button>
            <Button
              onClick={handleNext}
              disabled={
                (currentStep === 1 && (!formData.companyName || !formData.industry || !formData.businessModel)) ||
                (currentStep === 2 &&
                  (!formData.targetMarket || !formData.marketSize || !formData.customerPainPoints)) ||
                (currentStep === 3 && (!formData.problemStatement || !formData.solution || !formData.uniqueValue)) ||
                (currentStep === 4 && (!formData.competitors || !formData.competitiveAdvantage)) ||
                (currentStep === 5 &&
                  (!formData.marketingStrategy || !formData.salesChannels || !formData.pricingStrategy)) ||
                (currentStep === 6 && !formData.operationsModel) ||
                (currentStep === 7 && !formData.keyPersonnel) ||
                (currentStep === 8 &&
                  (!formData.revenueModel ||
                    !formData.revenueProjections ||
                    !formData.costStructure ||
                    !formData.fundingNeeded ||
                    !formData.useOfFunds)) ||
                (currentStep === 9 && (!formData.riskFactors || !formData.riskMitigation)) ||
                (currentStep === 10 && (!formData.timeline || !formData.milestones))
              }
            >
              下一步
            </Button>
          </div>
        )}

        {currentStep === 11 && generatedPlan && (
          <div className="flex justify-end mt-8">
            <Button variant="outline" onClick={onClose}>
              关闭
            </Button>
          </div>
        )}
      </DialogContent>
    </Dialog>
  )
}
